package com.qingshu.controller.custom;


import com.qingshu.common.annotation.Log;
import com.qingshu.common.entity.custom.Album;
import com.qingshu.common.entity.custom.Singer;
import com.qingshu.common.enums.BusinessType;
import com.qingshu.common.util.body.JsonResult;
import com.qingshu.common.util.body.ResultTool;
import com.qingshu.common.util.model.ModelUtil;
import com.qingshu.service.IAlbumService;
import com.qingshu.service.ISingerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Huzz
 * @since 2021-12-09
 */
@Api(tags = "专辑管理")
@RestController
@RequestMapping("/sys/album")
public class AlbumController {

    @Autowired
    private IAlbumService albumService;

    @Log(title = "专辑业务-添加专辑", businessType = BusinessType.INSERT, isSaveResponseParam = true)
    @ApiOperation(value = "添加专辑")
    @PostMapping("/addAlbum")
    public JsonResult addAlbum(@RequestBody Album model){
        return albumService.addAlbum((Album) ModelUtil.toEntityStatic(model, Album.class)) ? ResultTool.success() : ResultTool.fail();
    }

    @Log(title = "专辑业务-根据id进行查询", businessType = BusinessType.SELECT)
    @ApiOperation(value = "根据id进行查询")
    @GetMapping("/findAlbumById")
    public JsonResult findAlbumById(Integer albumId){
        return ResultTool.success(albumService.findAlbumById(albumId));
    }

    @Log(title = "专辑业务-根据名称进行查询", businessType = BusinessType.SELECT)
    @ApiOperation(value = "根据名称进行查询")
    @GetMapping("/findAlbumByName")
    public JsonResult findAlbumByName(@RequestParam String name){
        return ResultTool.success(albumService.findAlbumByName(name));
    }

}
